//
//  BottomPublish.m
//  FanweApp
//
//  Created by 志刚杨 on 2017/12/15.
//  Copyright © 2017年 xfg. All rights reserved.
//

#import "BottomPublish.h"
//#import "UIView+BorderLine.h"
#import "UIView+QMUI.h"
@interface BottomPublish()

@end

@implementation BottomPublish
{
    UITextField *txtTitle;
    UITextField *coinTitle;
}

-(instancetype)init
{
    self = [super init];
    if(self)
    {
        [IQKeyboardManager sharedManager].enable = YES;
        [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
        [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;        //输入框
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        self.backgroundColor = [UIColor whiteColor];
        
        txtTitle = [[UITextField alloc] init];
        txtTitle.placeholder = ASLocalizedString(@"建议输入8 ~ 5字");
        
        UIView *leftview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        QMUILabel *lefttitle = [[QMUILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        lefttitle.text = ASLocalizedString(@"  标题");
        [leftview addSubview:lefttitle];
        
        txtTitle.leftView = leftview;
        [txtTitle setLeftViewMode:UITextFieldViewModeAlways];
        txtTitle.frame = CGRectMake(5, 0, SCREEN_WIDTH, 60);
        [self addSubview:txtTitle];
        [txtTitle setQmui_borderPosition:QMUIBorderViewPositionBottom];
        
        coinTitle = [[UITextField alloc] init];
        coinTitle.placeholder = @"0";
        coinTitle.text = @"0";
        coinTitle.textContentType = UITextContentTypeCreditCardNumber;
        UIView *leftview1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        QMUILabel *lefttitle1 = [[QMUILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        lefttitle1.text = ASLocalizedString(@"  价格");
        [leftview1 addSubview:lefttitle1];
        
        coinTitle.leftView = leftview1;
        [coinTitle setLeftViewMode:UITextFieldViewModeAlways];
        coinTitle.frame = CGRectMake(5, 65, SCREEN_WIDTH, 60);
        [self addSubview:coinTitle];
        [coinTitle setQmui_borderPosition:QMUIBorderViewPositionBottom];
        
        //发布按钮
        QMUIFillButton *pushbutton = [[QMUIFillButton alloc] initWithFillColor:MainColor titleTextColor:[UIColor whiteColor]];
        pushbutton.frame = CGRectMake(15 , txtTitle.height + 25 + 60 , SCREEN_WIDTH - 30, 40);
        [pushbutton setTitle:ASLocalizedString(@"发布")forState:UIControlStateNormal];
        [self addSubview:pushbutton];
        [pushbutton addTarget:self action:@selector(handlePushDoneEvent:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

-(void)handlePushDoneEvent:(QMUIFillButton *)button
{
    
    if(StrValid(txtTitle.text))
    {
        if([self.delegage respondsToSelector:@selector(EditViewDoneWith:andMoney:)])
        {
            [self.delegage EditViewDoneWith:txtTitle.text andMoney:coinTitle.text];
        }
    }
    else
    {
        [[HUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请填写标题")];
    }

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
